#include<iostream>
#include<vector>
#include<string>
using namespace std;


//class Solution {
//public:
//    vector<int> missingTwo(vector<int>& nums)
//    {
//        int size = nums.size() + 2;
//        int ret = 0;
//        for (auto ch : nums) ret ^= ch;
//        for (int i = 1; i <= size; ++i) ret ^= i;
//
//        int def = ret & (-ret);
//        int count = 0;
//        while (def != 0)
//        {
//            def = def >> 1;
//            ++count;
//        }
//
//        vector<int> nums1;
//        vector<int> nums0;
//        for (int i = 1; i <= size; ++i)
//        {
//            if (((i >> count) & 1) == 1) nums1.push_back(i);
//            else nums0.push_back(i);
//        }
//
//        ret = 0;
//        for (auto ch : nums1) ret ^= ch;
//        vector<int> end;
//        end.push_back(ret);
//        ret = 0;
//        for (auto ch : nums0) ret ^= ch;
//        end.push_back(ret);
//        return end;
//    }
//};

class Solution {
public:
    vector<int> missingTwo(vector<int>& nums)
    {
        int size = nums.size() + 2;
        int ret = 0;
        for (auto ch : nums) ret ^= ch;
        for (int i = 1; i <= size; ++i) ret ^= i;

        int def = ret & (-ret);
        int count = 0;
        while (def != 0)
        {
            def = def >> 1;
            ++count;
        }

        int a = 0, b = 0;
        for (auto ch : nums)
        {
            if (((ch >> count) & 1) == 1) a ^= ch;
            else b ^= ch;
        }

        for (int i = 1; i <= size; ++i)
        {
            if (((i >> count) & 1) == 1) a ^= i;
            else b ^= i;
        }

        return{ a,b };
    }
};

class Solution {
public:
    vector<int> missingTwo(vector<int>& nums)
    {
        int size = nums.size() + 2;
        int ret = 0;
        for (auto ch : nums) ret ^= ch;
        for (int i = 1; i <= size; ++i) ret ^= i;

        int def = ret & (-ret);
        int count = 0;
        while (def != 1)
        {
            def = ((def >> 1) & 1);
            ++count;
        }

        int a = 0, b = 0;
        for (auto ch : nums)
        {
            if (((ch >> count) & 1) == 1) a ^= ch;
            else b ^= ch;
        }
        for (int i = 1; i <= size; ++i)
        {
            if (((i >> count) & 1) == 1) a ^= i;
            else b ^= i;
        }

        return{ a,b };
    }

int main()
{
    vector<int> nums = { 1 };
    Solution s1;
    nums = s1.missingTwo(nums);
    return 0;
}